package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.domain.MybatisReview;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult add(@PathVariable String name,@PathVariable Integer age,@PathVariable String sex){
        return toAjax(reviewService.saveData(name,age,sex));
    }
    @PostMapping("/saveData")
    public AjaxResult add(@RequestBody MybatisReview mybatisReview){
        return toAjax(reviewService.insertMybatisReview(mybatisReview));
    }
    /**=========================================================新增数据============================================*/
    @DeleteMapping("/remove")
    public AjaxResult remove(Long id){
        return toAjax(reviewService.deleteById(id));
    }

    /**=========================================================删除数据=============================================*/
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody MybatisReview mybatisReview){
        return toAjax(reviewService.updateMybatisReview(mybatisReview));
    }
    /**=========================================================修改数据=============================================*/
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        MybatisReview review = reviewService.selectMybatisReviewById(id);
        return AjaxResult.success(review);
    }

    @GetMapping("/list")
    public TableDataInfo list(@RequestBody MybatisReview mybatisReview){
        List<MybatisReview> list = reviewService.selectMybatisReviewList(mybatisReview);
        return getDataTablePage(list);
    }
    /**=========================================================查询数据=============================================*/

}